import request from '@/service'

export const getCateList = params => {
  return request({
    method: 'Get',
    url: 'categories',
    params
  })
}

// 1.7.1.参数列表
export const getParameterList = (id, params) => {
  return request({
    method: 'Get',
    url: `categories/${id}/attributes`,
    params: {
      sel: params
    }
  })
}

// 1.7.2. 添加动态参数或者静态属性
export const addParams = ({ id, attr_name: attrName, attr_sel: attrSel }) => {
  return request({
    method: 'post',
    url: `categories/${id}/attributes`,
    data: {
      attr_name: attrName,
      attr_sel: attrSel
    }
  })
}

// 1.7.4. 根据 ID 查询参数
export const theQueryParams = ({ id, attrId, attr_sel: attrSel }) => {
  return request({
    method: 'get',
    url: `categories/${id}/attributes/${attrId}`,
    data: {
      attr_sel: attrSel
    }
  })
}

// 1.7.5. 编辑提交参数
export const editorAddParams = ({
  id,
  attrId,
  attr_name: attrName,
  attr_sel: attrSel,
  attr_vals: attrVals
}) => {
  return request({
    method: 'put',
    url: `categories/${id}/attributes/${attrId}`,
    data: {
      attr_name: attrName,
      attr_sel: attrSel,
      attr_vals: attrVals
    }
  })
}

// 1.7.3. 删除参数
export const editorDeleteParams = (id, attrId) => {
  return request({
    method: 'delete',
    url: `categories/${id}/attributes/${attrId}`
  })
}
